package logic

import (
	"context"
	"errors"
	"house/model/mysql"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectListLogic {
	return &CollectListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectListLogic) CollectList(in *house.CollectListRequest) (*house.CollectListResponse, error) {
	// todo: add your logic here and delete this line

	var c mysql.Collect
	var cs []mysql.Collect
	if err := c.Find(); err != nil {
		logx.Error("查询失败")
		return nil, errors.New("查询失败")
	}
	var collect []*house.CollectList
	mysql.DB.Find(&cs)
	for _, k := range cs {
		collect = append(collect, &house.CollectList{
			Collects: k.Collexts,
			HouseId:  k.HouseId,
			UserId:   k.UserId,
		})
	}

	return &house.CollectListResponse{
		List: collect,
	}, nil
}
